package juc.c_001;/*
   Talk is cheap. Show me the code.
 */

import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Date 2021/6/6
 * @Author liudl
 */
public class T8 {
    String name;
    double balance;

    public synchronized void set(String name, double balance) throws InterruptedException {
        this.name = name;
        TimeUnit.SECONDS.sleep(2);
        this.balance = balance;
    }
    public /*synchronized*/ double getBalance() {
        return this.balance;
    }

    public static void main(String[] args) throws InterruptedException {
        T8 t8 = new T8();
        new Thread(() -> {
            try {
                t8.set("zhangs", 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        TimeUnit.SECONDS.sleep(1);
        System.out.println(t8.getBalance());
    }
}